#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

#define long long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    long A, B, C;
    vector<long> a(10000001);
    scanf("%d%lld%lld%lld%ld", &n, &A, &B, &C, &a[1]);
    for (int i = 2; i <= n; ++i) {
        a[i] = (a[i - 1] * A + B) % 100000001;
    }
    for (int i = 1; i <= n; ++i) {
        a[i] = a[i] % C + 1;
    }
    double exp = 0.0;
    for (int i = 2; i <= n; ++i) {
        exp += (double)min(a[i - 1], a[i]) / (double)(a[i - 1] * a[i]);
    }
    exp += (double)min(a[n], a[1]) / (double)(a[n] * a[1]);
    printf("%.3f\n", exp);
}
